package com.diary.database;

import com.diary.DBUtils;

import java.sql.*;

public class SelectTable {

    public static boolean select(String username) {

        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        DatabaseMetaData dbMetaData = null;

        try {
            connection = DBUtils.getConnection();
            dbMetaData = connection.getMetaData();


            resultSet = dbMetaData.getTables(null, null, username, null);

//            String sql = "SHOW TABLES LIKE ?";

//            preparedStatement = connection.prepareStatement(sql);

//            preparedStatement.setString(1,username);

//            resultSet = preparedStatement.executeQuery();




//            System.out.println("查询表名");
//            System.out.println(resultSet.next());

            return resultSet.next();


        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        } finally {
            //dbMate 不需要手动关闭，会随着connection关闭而关闭
            DBUtils.close(resultSet, preparedStatement, connection);
        }
    }
}






